package com.iretailer.report.analyze.commonUtil;

import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.http.HttpResponseStatus;

/**
 * @Auther: xjw
 * @Date: 2018/12/12 13:44
 * @Description:
 */
public class ResponeResultType {
    private ChannelFutureListener cfl;
    private HttpResponseStatus hrs;

    public ResponeResultType() {
    }

    public ResponeResultType(ChannelFutureListener cfl, HttpResponseStatus hrs) {
        this.cfl = cfl;
        this.hrs = hrs;
    }

    public ChannelFutureListener getCfl() {
        return cfl;
    }

    public void setCfl(ChannelFutureListener cfl) {
        this.cfl = cfl;
    }

    public HttpResponseStatus getHrs() {
        return hrs;
    }

    public void setHrs(HttpResponseStatus hrs) {
        this.hrs = hrs;
    }

    public static enum CFLType {
        CLOSE, CLOSE_ON_FAILURE, FIRE_EXCEPTION_ON_FAILURE;

        private CFLType() {

        }
    }

    public static ResponeResultType badResult_close = new ResponeResultType(ChannelFutureListener.CLOSE, HttpResponseStatus.BAD_REQUEST);
    public static ResponeResultType badResult_close_on_failure = new ResponeResultType(ChannelFutureListener.CLOSE_ON_FAILURE, HttpResponseStatus.BAD_REQUEST);
    public static ResponeResultType badResult_fire = new ResponeResultType(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, HttpResponseStatus.BAD_REQUEST);


    public static ResponeResultType getBadRequest(CFLType type) {
        if (type == null) {
            return badResult_fire;
        }
        switch (type) {
            case CLOSE:
                return badResult_close;
            case CLOSE_ON_FAILURE:
                return badResult_close_on_failure;
            case FIRE_EXCEPTION_ON_FAILURE:
                return badResult_fire;
            default:
                return badResult_fire;
        }
    }

    public static ResponeResultType okResult_close = new ResponeResultType(ChannelFutureListener.CLOSE, HttpResponseStatus.OK);
    public static ResponeResultType okResult_close_onfailure = new ResponeResultType(ChannelFutureListener.CLOSE_ON_FAILURE, HttpResponseStatus.OK);
    public static ResponeResultType okResult_fire = new ResponeResultType(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, HttpResponseStatus.OK);


    public static ResponeResultType getOkRequest(CFLType type) {
        if (type == null) {
            return okResult_close_onfailure;
        }
        switch (type) {
            case CLOSE:
                return okResult_close;
            case CLOSE_ON_FAILURE:
                return okResult_close_onfailure;
            case FIRE_EXCEPTION_ON_FAILURE:
                return okResult_fire;
            default:
                return okResult_close;
        }
    }

}
